package com.jiazhong.shixi.controller;

import com.jiazhong.shixi.bean.Bingli;
import com.jiazhong.shixi.bean.Yisheng;
import com.jiazhong.shixi.mapper.YishengMapper;
import com.jiazhong.shixi.util.JsonResult;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/yis")
public class YishengController {
    @Resource
    private YishengMapper yishengMapper;

    @RequestMapping("/denglu")
    public JsonResult denglu(Yisheng yisheng) {
        System.out.println(yisheng);
        Yisheng y = yishengMapper.interfact(yisheng);
        if ( y == null) {
            //  登陆失败
            JsonResult result
                    = new JsonResult(false, 500, null,"账号或密码错误");
            return result;
        } else {
            //  登陆成功
            JsonResult result = new JsonResult(true, 200,y,"");
            return result;
        }
    }

    @RequestMapping("/add")
    public JsonResult add(Yisheng yisheng) {
        yishengMapper.add(yisheng);
        JsonResult result = new JsonResult(true, 200,"success","");
        return result;
    }
    @RequestMapping("/chaxun")
    public JsonResult chaxun() {
        List<Bingli> list = yishengMapper.bingli();
        JsonResult result = new JsonResult(true, 200,list,"");
        return result;
    }
    @RequestMapping("/kanb")
    public JsonResult kanb(Yisheng id) {
        yishengMapper.kanbing(id);
        JsonResult result = new JsonResult(true, 200,"success","");
        return result;
    }
}
